// Copyright (c) 2025 Huawei Technologies Co., Ltd.
// openUBMC is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//         http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Description: 获取VMM相关信息

#ifndef GET_VMM_INFO_HPP
#define GET_VMM_INFO_HPP

#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <stdexcept>
#include "KvmClient.hpp"


class GetVmmInfo {
private:
    std::pair<int, std::vector<uint8_t>> SendGetVmmStatusReq(const std::vector<uint8_t>& body);
    void RecvGetVmmStatusRsp(const std::vector<uint8_t>& body);
    std::pair<int, std::vector<uint8_t>> SendGetVmmPortReq(const std::vector<uint8_t>& body);
    void RecvGetVmmPortRsp(const std::vector<uint8_t>& body);

public:
    explicit GetVmmInfo(KvmClient& client);
    ~GetVmmInfo();

    KvmClient& client_;
    std::mutex getVmmStatusMutex_; // 防止获取VMM使能状态重入
    std::mutex getVmmPortMutex_; // 防止获取VMM端口号重入
    std::condition_variable getVmmStatusCv_;
    std::condition_variable getVmmPortCv_;
    uint8_t getVmmStatusRsp_; // 0xff表示失败后的无效值
    std::vector<uint8_t> getVmmPortRsp_;
};

#endif // GET_VMM_INFO_HPP